package com.xingongchang.baolebei.protocol;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;
import com.insthub.BeeFramework.model.BaseModel;

@Table(name = "Good_id")
public class Good_id extends BaseModel{
	          @Column(name = "formated_shop_price")
	        public String formated_shop_price;
	          @Column(name = "goods_id")
			public int goods_id;
	          @Column(name = "goods_number")
			public int goods_number;
			@Column(name = "img")
			public PHOTO img;
			@Column(name = "subtotal")
	        public String subtotal;
			@Column(name = "name")
			public String name;
			public static Good_id fromJson(JSONObject jsonObject)
					throws JSONException {
				if (null == jsonObject) {
					return null;
				}

				Good_id localItem = new Good_id();

				JSONArray subItemArray;
				localItem.img = PHOTO.fromJson(jsonObject.optJSONObject("img"));
				localItem.formated_shop_price = jsonObject.optString("formated_shop_price");

				localItem.goods_number = jsonObject.optInt("goods_number");

				localItem.goods_id = jsonObject.optInt("goods_id");

				localItem.subtotal = jsonObject.optString("subtotal");

				localItem.name= jsonObject.optString("name");

				return localItem;
			}

			public JSONObject toJson() throws JSONException {
				JSONObject localItemObject = new JSONObject();
				JSONArray itemJSONArray = new JSONArray();
				if (null != img) {
					localItemObject.put("img", img.toJson());
				}
				localItemObject.put("goods_number", goods_number);
				localItemObject.put("goods_id", goods_id);
				localItemObject.put("subtotal", subtotal);
				localItemObject.put("name", name);
				localItemObject.put("formated_shop_price", formated_shop_price);
				return localItemObject;
			}
}
